{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Installation\n",
    "\n",
    ":label:`chap_installation`\n",
    "\n",
    "\n",
    "In order to get you up and running for hands-on learning experience,\n",
    "we need to set you up with an environment for running Python,\n",
    "Jupyter notebooks, the relevant libraries,\n",
    "and the code needed to run the book itself.\n",
    "\n",
    "## Installing JDK 11 (not jre)\n",
    "\n",
    "JDK 11 (or above) are required to run the examples provided in this folder.\n",
    "\n",
    "To confirm the java path is configured properly, run:\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```bash\n",
    "java --list-modules | grep \"jdk.jshell\"\n",
    "\n",
    "> jdk.jshell@12.0.1\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Install jupyter notebook on python3\n",
    "\n",
    "Use the following command to install Jupyter Notebook in Python 3:\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```bash\n",
    "pip3 install jupyter\n",
    "\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Install Java kernel for jupyter notebook\n",
    "By default jupyter notebook runs only Python3. You need to install the Java kernel to run Java code such as DJL.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```bash\n",
    "git clone https://github.com/frankfliu/IJava.git\n",
    "cd IJava/\n",
    "./gradlew installKernel\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Downloading the D2L-Java Notebooks\n",
    "\n",
    "Next, we need to download the code for this book. You can clone our \n",
    "[repository](https://github.com/aws-samples/d2l-java) and browse all the notebooks\n",
    "using Jupyter Notebook."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```bash\n",
    "git clone https://github.com/aws-samples/d2l-java\n",
    "cd d2l-java\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Running Jupyter Notebook\n",
    "Once the above dependencies are installed, we can now open the Jupyter notebook by running:\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```bash\n",
    "jupyter notebook\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "At this point, you can open http://localhost:8888 (it usually opens automatically) in your Web browser. Then we can run the code for each section of the book. Remember to switch the Kernel to Java instead of Python3.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Adding the dependencies on DJL and the MXNet engine\n",
    "\n",
    "You can add maven dependencies on DJL and MXNet by adding a Java cell including:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```java\n",
    "// Add the maven dependencies\n",
    "%maven ai.djl:api:0.8.0\n",
    "%maven org.slf4j:slf4j-api:1.7.26\n",
    "%maven org.slf4j:slf4j-simple:1.7.26\n",
    "        \n",
    "// See https://github.com/awslabs/djl/blob/master/mxnet/mxnet-engine/README.md\n",
    "// for more MXNet library selection options\n",
    "%maven ai.djl.mxnet:mxnet-native-auto:1.7.0-b\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now you can import and run different modules in DJL.\n",
    "\n",
    "\n",
    "## GPU Support\n",
    "\n",
    "\n",
    ":label:`subsec_gpu`\n",
    "\n",
    "\n",
    "We recommend using the \"ai.djl.mxnet:mxnet-native-auto\" dependency. When you include this, DJL will detect your operating system and whether you have a GPU available. It will automatically download the corresponding MXNet GPU native libraries for your environment. No specific requirement needed to run the notebook on GPU machines. To use specific builds of MXNet engine, please refer to our [documentation](https://github.com/awslabs/djl/tree/master/mxnet/mxnet-engine)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "## Exercises\n",
    "\n",
    "1. Download the code for the book and install the runtime environment.\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
